//
//  StatusCellBottomView.swift
//  Sinaweibo
//
//  Created by 谌桃 on 15/12/2.
//  Copyright © 2015年 ryan.chen. All rights reserved.
//

import UIKit

class StatusCellBottomView: UIView {

    //MARK: 监听方法
    @objc private func retweetedBtnDidClick() {
        let temp = TempViewController()
        
        retweetedBtn.navController()?.pushViewController(temp, animated: true)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
        super.init(coder: aDecoder)
        setupUI()
    }

    //懒加载子视图
    private func setupUI() {
        self.backgroundColor = UIColor(white: 0.98, alpha: 1)
        
        addSubview(retweetedBtn)
        addSubview(composeBtn)
        addSubview(likeBtn)
        //设置布局
        retweetedBtn.snp_makeConstraints { (make) -> Void in
            make.top.left.bottom.equalTo(self)
        }
        composeBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedBtn.snp_right)
            make.top.bottom.equalTo(self)
            make.width.equalTo(retweetedBtn.snp_width)
        }
        
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(composeBtn.snp_right)
            
            //三等分的第一个条件 添加右边约束
            make.right.equalTo(self.snp_right)
            make.width.equalTo(composeBtn.snp_width)
            make.top.bottom.equalTo(self)
        }
        
        let sepView1 = sepView()
        addSubview(sepView1)
        let sepView2 = sepView()
        addSubview(sepView2)
        let w = 0.5
        let scale = 0.4
        
        //设置分隔线的布局
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedBtn.snp_right)
            make.width.equalTo(w)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
        }
        
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(composeBtn.snp_right)
            make.width.equalTo(w)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
        }
        
        //添加点击事件
        retweetedBtn.addTarget(self, action: "retweetedBtnDidClick", forControlEvents: .TouchUpInside)
        
    }
    
    private func sepView() -> UIView {
        let v = UIView()
        v.backgroundColor = UIColor.lightGrayColor()
        return v
    }
    
    //懒加载视图
    private lazy var retweetedBtn: UIButton = UIButton(title: "转发", backImage: nil, color: UIColor.darkGrayColor(), fontSize: 10, isNeedHighlighted: false, imageName: "timeline_icon_retweet")
    
    private lazy var composeBtn: UIButton = UIButton(title: "评论", backImage: nil, color: UIColor.darkGrayColor(), fontSize: 10, isNeedHighlighted: false, imageName: "timeline_icon_comment")
    
    private lazy var likeBtn: UIButton = UIButton(title: "赞", backImage: nil, color: UIColor.darkGrayColor(), fontSize: 10, isNeedHighlighted: false, imageName: "timeline_icon_unlike")

}
